package com.ssy.lingxi.contract.serviceimpl;

import com.ssy.lingxi.contract.entity.SignatureAccount;
import com.ssy.lingxi.contract.entity.SignatureOrganization;
import com.ssy.lingxi.contract.model.bo.sign.ContractParamMemberFillBO;
import com.ssy.lingxi.contract.model.bo.sign.SignAuthDetailBO;
import com.ssy.lingxi.contract.model.constant.sign.SignatureAuthTypeEnum;

import java.util.Objects;

/**
 * 合同签署服务实现基类
 * @author yzc
 * @version 2.0.0
 * @date 2020/9/1
 */
public class BaseContractSignatureService {

    public ContractParamMemberFillBO getContractFillParam(SignAuthDetailBO signAuthDetail) {
        ContractParamMemberFillBO contractParamMemberFillBO = new ContractParamMemberFillBO();

        // 企业认证
        if (SignatureAuthTypeEnum.LEGAL_PERSON.getCode().equals(signAuthDetail.getAuthType())
                || SignatureAuthTypeEnum.AGENT.getCode().equals(signAuthDetail.getAuthType())) {
            // 机构账户信息
            SignatureOrganization organization = signAuthDetail.getOrganization();
            if (Objects.isNull(organization)) {
                return null;
            }

            contractParamMemberFillBO.setOrgName(organization.getName());
            contractParamMemberFillBO.setRepName(organization.getOrgLegalName());
            contractParamMemberFillBO.setMobile(organization.getOrgLegalMobile());

            // TODO 测试数据
            contractParamMemberFillBO.setBankName("中国工商银行广州粤秀支行(测)");
            contractParamMemberFillBO.setBankAccount("广州市数商云网络科技有限公司(测)");
            contractParamMemberFillBO.setBankCardNo("3602015009201436525(测)");
            contractParamMemberFillBO.setAddress("广州市海珠区新港东路1068号605房");
        }

        // 个人认证
        if (SignatureAuthTypeEnum.PERSONAL.getCode().equals(signAuthDetail.getAuthType())) {
            // 个人账户信息
            SignatureAccount account = signAuthDetail.getAccount();
            if (Objects.isNull(account)) {
                return null;
            }

            contractParamMemberFillBO.setOrgName(account.getName());
            contractParamMemberFillBO.setRepName(account.getName());
            contractParamMemberFillBO.setMobile(account.getMobile());

            // TODO 测试数据
            contractParamMemberFillBO.setBankName("中国工商银行广州粤秀支行(测)");
            contractParamMemberFillBO.setBankAccount("广州市数商云网络科技有限公司(测)");
            contractParamMemberFillBO.setBankCardNo("3602015009201436525(测)");
            contractParamMemberFillBO.setAddress("广州市海珠区新港东路1068号605房");
        }

        return contractParamMemberFillBO;
    }


//    public void fillContractParam(ContractParamFillBO paramFillBO, ProcurementOrderDetailsResponse orderDetail) {
//        BigDecimal freightAmount = Objects.isNull(orderDetail.getFreight()) ? BigDecimal.ZERO : BigDecimal.valueOf(orderDetail.getFreight());
//        BigDecimal productAmount = Objects.isNull(orderDetail.getSumPrice()) ? BigDecimal.ZERO : BigDecimal.valueOf(orderDetail.getSumPrice());
//
//        List<OrderProductBO> goodList = orderDetail.getOrderProductRequests().stream().map(e -> {
//            OrderProductBO orderProduct = new OrderProductBO();
//            orderProduct.setBrand(e.getBrand());
//            orderProduct.setProduct(e.getProductName());
//            orderProduct.setModel("");
//            orderProduct.setCount(e.getPurchaseCount());
//            orderProduct.setPrice(BigDecimal.valueOf(e.getPrice()));
//            orderProduct.setAmount(BigDecimal.valueOf(e.getMoney()));
//            orderProduct.setTotal(BigDecimal.valueOf(e.getMoney()));
//            orderProduct.setRemark("");
//
//            return orderProduct;
//        }).collect(Collectors.toList());
//
//        OrderBO orderBO = new OrderBO();
//        orderBO.setOrderProductList(goodList);
//        orderBO.setProductAmount(productAmount);
//        orderBO.setFreightAmount(freightAmount);
//        orderBO.setTotalAmount(productAmount.add(freightAmount));
//
//        paramFillBO.setOrderBO(orderBO);
//    }

//    public void fillContractParamPreOrder(ContractParamFillBO paramFillBO, List<OrderProductRequest> orderProductList, BigDecimal freightAmount, BigDecimal productAmount) {
//        freightAmount = Objects.isNull(freightAmount) ? BigDecimal.ZERO : freightAmount;
//        productAmount = Objects.isNull(productAmount) ? BigDecimal.ZERO : productAmount;
//
//        List<OrderProductBO> goodList = orderProductList.stream().map(e -> {
//            OrderProductBO orderProduct = new OrderProductBO();
//            orderProduct.setBrand(e.getBrand());
//            orderProduct.setProduct(e.getProductName());
//            orderProduct.setModel("");
//            orderProduct.setCount(e.getPurchaseCount());
//            orderProduct.setPrice(BigDecimal.valueOf(e.getPrice()));
//            orderProduct.setAmount(BigDecimal.valueOf(e.getMoney()));
//            orderProduct.setTotal(BigDecimal.ZERO);
//            orderProduct.setRemark("");
//
//            return orderProduct;
//        }).collect(Collectors.toList());
//
//        OrderBO orderBO = new OrderBO();
//        orderBO.setOrderProductList(goodList);
//        orderBO.setProductAmount(productAmount);
//        orderBO.setFreightAmount(freightAmount);
//        orderBO.setTotalAmount(productAmount.add(freightAmount));
//        paramFillBO.setOrderBO(orderBO);
//
//    }
}